function pageReady() {
    layui.use(['form', 'layer', 'layedit', 'laydate', 'upload'], function () {
        var form = layui.form;
        $("#valCode").val(layuiFunciton.randomChar(6));
        layer = parent.layer === undefined ? layui.layer : top.layer,
            laypage = layui.laypage,
            upload = layui.upload,
            layedit = layui.layedit,
            laydate = layui.laydate,
            $ = layui.jquery;
        form.verify({
            number: [
                /^[1-9]\d*$/
                , '只能输入整数'
            ],
            code: function (value) {

                var codeDatas = codes(value);
                if (codeDatas == false) {
                    return "该编号已存在"
                }
            },
            valCode: [
                /^[\w\d\.]*$/
                , '字典值编码由字母、数字、_、.组成'
            ]
        })
        form.on("submit(addNews)", function (data) {
            if ("YWLX_T" == $("#typeCode").val() || "YWLX_S" == $("#typeCode").val() || "YWLX_G" == $("#typeCode").val()) {
                var descriptions = [];
                $("input:checkbox:checked").each(function (index, element) {
                    descriptions.push(element.value)
                });
                if (descriptions.length == 0) {
                    $("#description").val("");
                } else {
                    $("#description").val(descriptions.join(","));
                }
            }
            //弹出loading
            var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.1});
            // 实际使用时的提交信息
            $.post("/tu/sys/dictVal/addEntity", {
                typeCode: $("#typeCode").val(),  //
                valName: $("#valName").val(), //
                description: $("#description").val(),
                valCode: $("#valCode").val(),
                sortIndex: $("#sortIndex").val(),
            }, function (res) {

            })
            setTimeout(function () {
                top.layer.close(index);
                top.layer.msg("添加成功！");
                layer.closeAll("iframe");
                layuiFunciton.closeOpen();
                ////刷新父页面
                //parent.location.reload();
            }, 500);
            return false;
        });
    });
    function codes(value) {
        var add;
        $.ajax({//异步请求返回给后台
            url: '/tu/sys/dictVal/checkValCodeIsExist',
            type: 'POST',
            async: false,
            data: {
                valCode: value
            },
            dataType: 'json',
            success: function (data) {
                add = data;
                //这里获取到数据执行显示
            }
        });
        return add;
    }

    //查询
    if ("YWLX_T" == $("#typeCode").val() || "YWLX_S" == $("#typeCode").val() || "YWLX_G" == $("#typeCode").val()) {
        layuiFunciton.ajaxRequest({
            url: layuiFunciton.URL + '/sys/dictVal/getByTypeCode?page=1&limit=999&typeCode=FYLX',
            method: 'get',
            success: function (data) {
                var descriptionHtml = '';
                $(data).each(function (index, obj) {
                    descriptionHtml += '<input type="checkbox" name="description" value="' + obj.valCode + '" title="' + obj.valName + '">';
                });
                $("#descriptionHtml").html(descriptionHtml);
            }
        });
    } else if ("FYLX" == $("#typeCode").val()) {
        layuiFunciton.ajaxRequest({
            url: layuiFunciton.URL + '/sys/dictVal/getByTypeCode?page=1&limit=999&typeCode=SKDW',
            method: 'get',
            success: function (data) {
                var descriptionHtml = '';
                $(data).each(function (index, obj) {
                    if (index == 0) {
                        descriptionHtml += '<option value="">请选择</option><option value="' + obj.valCode + '">' + obj.valName + '</option>';
                    } else {
                        descriptionHtml += '<option value="' + obj.valCode + '">' + obj.valName + '</option>';
                    }
                });
                $("#description").html(descriptionHtml);
            }
        });
    }
}

